﻿using System;
using System.Collections.Generic;
using System.Text;
using WindowsInput;
using WindowsInput.Native;

namespace Tornado
{
    public class SignalProcessZoom : SignalProcesser
    {

        KeyboardSimulator keyboard = new KeyboardSimulator();

        public override SignalCodes Code
        {
            get { return SignalCodes.SCREEN; }
        }
        public override void Process(ref SignalPacket p)
        {
            VirtualKeyCode[] trlAlt = {VirtualKeyCode.RCONTROL,VirtualKeyCode.MENU};
            switch ((ScreenExCode)p.ExtensionCode)
            {
                case ScreenExCode.Screen:
                    switch (BitConverter.ToInt32(p.Argument, 0))
                    { 
                        case 0:
                            WinPower.MonitorOff();
                            break;
                        case 1:
                            WinPower.MonitorOn();
                            break;
                        case 2:
                            WinPower.ScreenSave();
                            break;
                    }
                    break;
                case ScreenExCode.Projector:
                    switch (BitConverter.ToInt32(p.Argument, 0))
                    {
                        case 0:
                            WinPower.ChangeScreen("internal");
                            break;
                        case 1:
                            WinPower.ChangeScreen("clone");
                            break;
                        case 2:
                            WinPower.ChangeScreen("extend");
                            break;
                        case 3:
                            WinPower.ChangeScreen("external");
                            break;
                    }
                    break;
                case ScreenExCode.Zoom:
                    switch (BitConverter.ToInt32(p.Argument, 0))
                    {
                        case 0:
                            keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.OEM_PLUS);
                            break;
                        case 1:
                            if (WinProcess.isMagnifyRunning())
                                keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.OEM_MINUS);
                            break;
                        case 2:
                            if (WinProcess.isMagnifyRunning())
                                keyboard.ModifiedKeyStroke(trlAlt, VirtualKeyCode.VK_D);
                            break;
                        case 3:
                            if (WinProcess.isMagnifyRunning())
                                keyboard.ModifiedKeyStroke(trlAlt, VirtualKeyCode.VK_L);
                            break;
                        case 4:
                            if (WinProcess.isMagnifyRunning())
                                keyboard.ModifiedKeyStroke(trlAlt, VirtualKeyCode.VK_F);
                            break;
                        case 5:
                            if (WinProcess.isMagnifyRunning())
                                keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.ESCAPE);
                            break;
                    }
                    break;
            }
        }
    }
}
